package com.zhulin.android.edoctor.parsehandler;

import java.io.ByteArrayOutputStream;

import org.json.JSONException;
import org.json.JSONObject;

import com.zhulin.android.edoctor.jsonobject.OUTGetCaseInfo;
import com.zhulin.android.edoctor.net.ParseHandler;

public class GetCaseInfoParseHandler implements ParseHandler{

	@SuppressWarnings("finally")
	@Override
	public Object handle(ByteArrayOutputStream str) {
		String ret = new String(str.toByteArray()).trim();
		OUTGetCaseInfo outGetCaseInfo=new OUTGetCaseInfo();
		
		try {
			JSONObject jsonObject=new JSONObject(ret);
			
			int result=jsonObject.getInt(Result);
			outGetCaseInfo.setResult(result);
			if(result==1){
				outGetCaseInfo.setPicture1(jsonObject.getString("Picture1"));
				outGetCaseInfo.setPicture2(jsonObject.getString("Picture2"));
				outGetCaseInfo.setSex(jsonObject.getString("Sex"));
				outGetCaseInfo.setAge(jsonObject.getInt("Age"));
				outGetCaseInfo.setLocation(jsonObject.getString("Location"));
				outGetCaseInfo.setComplain(jsonObject.getString("Complain"));
				outGetCaseInfo.setAbstract(jsonObject.getString("Abstract"));
				outGetCaseInfo.setDiagnose(jsonObject.getString("Diagnose"));
				outGetCaseInfo.setTreatPlan(jsonObject.getString("TreatPlan"));
				outGetCaseInfo.setTreatResult(jsonObject.getString("TreatResult"));
				outGetCaseInfo.setLaudCount(jsonObject.getInt("LaudCount"));
				outGetCaseInfo.setCommentCount(jsonObject.getInt("CommentCount"));
				outGetCaseInfo.setUploadDate(jsonObject.getString("UploadDate"));
			}else{
				outGetCaseInfo.setDescription(jsonObject.getString(Descption));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		finally{
			return outGetCaseInfo;
		}
	}

}
